<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>四川省工程建设领域项目信息、信用信息公开维护平台</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/reset.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/main.css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/My97DatePicker4/WdatePicker.js"></script>
<script src="<%=request.getContextPath()%>/scripts/jquery-latest.pack.js"></script>
<script src="<%=request.getContextPath()%>/scripts/jquery.form.js"></script>
<script type="text/javascript">
var submitFlag = true;
function check(){
	var f = document.getElementById("form1");
	if (f.userPassword.value == ""){
		alert("必须填写密码");
		f.userPassword.focus();
		return false;
	}
	if (f.userPassword.value.length < 4){
		alert("密码至少需要四位");
		f.userPassword.focus();
		return false;
	}
	if (f.orgName.value == ""){
		alert("必须填写组织机构名称");
		f.deptName.focus();
		return false;
	}
	if(f.orgCode.value != ""){
		var oCode = f.orgCode.value.replace('-','');
		if(oCode.indexOf('-')>0 || oCode.indexOf('_')>0){
			alert('请正确组织机构代码，短横杠"-" 下划线"_" 等字符不必输入');
			return false;
		}
		if (f.orgCode.value.length != 9){
			alert("请输入正确的组织机构代码");
			f.orgCode.focus();
			return false;
		}
		f.orgCode.value = f.orgCode.value.replace('-','');
	}

	if (f.responser.value == ""){
		alert("必须填写法人代表");
		f.responser.focus();
		return false;
	}
	if (f.companyAddr.value == ""){
		alert("必须填写地址");
		f.companyAddr.focus();
		return false;
	}
	
	if (f.companyAddr.value == ""){
		alert("必须填写地址");
		f.companyAddr.focus();
		return false;
	}
	if (f.contacter.value == ""){
		alert("必须填写联系人");
		f.contacter.focus();
		return false;
	}
	if (f.phone.value == ""){
		alert("必须填写电话");
		f.phone.focus();
		return false;
	}
	if (f.email.value == ""){
		alert("必须填写电子邮件");
		f.email.focus();
		return false;
	}
	return true;
}

function checkOrgCode(obj)
{
	if (obj.value != "")
	{
		if(obj.value.length < 9){
			var obj = document.getElementById("oCd");
			obj.innerHTML='<font color="#FF9966">该组织机构代码不正确</font>';
			return;
		}
		setTimeout(function(){checkOrgCodeDB(obj);}, 2000);
	}
}

function checkOrgCodeDB(obj)
{
	var userID = document.getElementById("userID").value;
	var options={type:"POST", 
				url:"<%=request.getContextPath()%>/user/orgCodeAuthWithUserID?orgCode="+obj.value+"&userID"+userID, 
				dataType:"json", success: checkOrgCodeHandle};
	$.ajax(options);
}

function checkOrgCodeHandle(data,status) {
	var obj = document.getElementById("oCd");
	if(status){
		if (data.result == 0){
			obj.innerHTML='<font color="#669933">该组织机构代码可以注册</font>';
		}
		else{
			obj.innerHTML='<font color="#FF9966">该组织机构代码已被注册</font>';
		}
	}
	else{
		obj.innerHTML='<font color="#FFFF00">无法检测组织机构代码</font>';
	}
}

function checkAccAndOrgCode(){
	var userAccount = $('#userAccount').val();
	var orgCode = $('#orgCode').val();
	var userID = $('#userID').val();
	submitFlag = false;
	var options={type:"POST",
			data: "userAccount="+userAccount+"&orgCode="+orgCode+"&userID="+userID,
			url:"<%=request.getContextPath()%>/user/userAccountAndOrgCodeAuthWithUserID", 
			dataType:"json", success: checkAccAndOrgCodeHandle};
	$.ajax(options);
}

function checkAccAndOrgCodeHandle(data,status){
	submitFlag = true;
	if(status){
		if (data.result == 0){
			document.getElementById('form1').submit();
		}
		else{
			alert(data.msg);
			var tarUrl = $('#tarUrl').val();
			if(tarUrl != "" && tarUrl != null){
				location.href = tarUrl;
			}
		}
	}
	else{
		alert('网络连接异常，请联系管理员');
	}
}

function edit(){
	if(!submitFlag){
		alert('请求已提交，请稍候');
		return;
	}
	if(!check()){
		return;
	}
	checkAccAndOrgCode();
}
</script>
</head>
<body>
<form method="post" id="form1" name="form1" onsubmit="return check(this);">

<table class="top">
  <tr>
    <td width="40" class="topl"></td>
    <td width="840"><div class="plat_title"><img src="<%=request.getContextPath()%>/images/toptitle.gif" /></div></td>
    <td width="21"><a href="#" class="top_drop_btn"></a></td>
    <td width="20"><a href="#" class="maxbtn"></a></td>
    <td width="29"><a href="#" class="closebtn"></a></td>
  </tr>
</table>
<table class="content">
  <tr>
    <td class="main_l"></td>
    <td class="main_lbar"></td>
    <td width="918" valign="top">
	<div class="banner"><img src="<%=request.getContextPath()%>/images/banner.jpg" /></div>
	<div class="op_con">
    <table class="regtable">
  <tr>
<th colspan="2">帐号信息</th>
  </tr>
  <tr>
  <td colspan="2"></td>
  </tr>
 
  <tr>
    <td class="w02">帐号</td>
    <td><input type="text" class="intt" value="${user.userAccount}" disabled="disabled"/><b>*</b></td>
  </tr>
  <tr>
    <td class="w02">密码</td>
    <td><input type="text" class="intt" id="userPassword" name="userPassword" value="${user.userPassword}" maxlength="6"/><b>*</b></td>
  </tr>
  <tr>
    <td class="w02">组织机构名称</td>
    <td><input type="text" class="intt" id="orgName" name="orgName" value="${user.orgName}" maxlength="50"/><b>*</b></td>
  </tr>
  <tr>
    <td class="w02">组织机构代码</td>
    <td><input type="text" class="intt" id="orgCode" name="orgCode" value="${user.orgCode}" maxlength="9"/><b>*</b></td>
  </tr>
  <tr>
    <td class="w02">成立时间</td>
    <td><input type="text" class="intt" id="estDate" name="estDate" value="${user.estDate}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"/></td>
  </tr>
  <tr>
    <td class="w02">法人代表</td>
    <td><input type="text" class="intt" id="responser" name="responser" value="${user.responser}" maxlength="50"/><b>*</b></td>
  </tr>
  <tr>
    <td class="w02">地址</td>
    <td><input type="text" class="intt" id="companyAddr" name="companyAddr" value="${user.companyAddr}" maxlength="50"/><b>*</b></td>
  </tr>
  <tr>
    <td class="w02">联系人</td>
    <td><input type="text" class="intt" id="contacter" name="contacter" value="${user.contacter}" maxlength="50"/><b>*</b></td>
  </tr>
  <tr>
    <td class="w02">联系电话</td>
    <td><input type="text" class="intt" id="phone" name="phone" value="${user.phone}" maxlength="50"/><b>*</b></td>
  </tr>
  <tr>
    <td class="w02">电子邮件</td>
    <td><input type="text" class="intt" id="email" name="email" value="${user.email}" maxlength="50"/><b>*</b><span>找回密码必填</span></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
    <input type="hidden" name="tarUrl" id="tarUrl" value="${tarUrl}"/>
    <input type="hidden" name="userID" id="userID" value="${user.userID}"/>
    <input style="margin:0 0 0 5px;" type="button" value="保存" class="btn40" onclick="edit();"/></td>
  </tr>
    <tr>
  <td colspan="2"></td>
  </tr>
</table>

	</div>
	</td>
    <td class="main_rbar"></td>
	<td class="main_r"></td>
  </tr>
</table>
</form>
<table class="bot">
	<tr>
		<td width="41"><div class="botl"></div></td>
		<td width="867"></td>
		<td width="42"><div class="exit"></div></td>
	</tr>
</table>
<c:import url="/foot.jsp" />
</body>
</html>
